package com.sjtu.vfact.textual.algorithm;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;


public abstract class Facta {
	
	public static final String PROGRESS = "progress";
	public static final String DOCUMENT = "document";
	
	private int progress;
	private int actualDocument;
		
	private PropertyChangeSupport pcs;
	
	public Facta(){
		pcs = new PropertyChangeSupport(this);
		progress = 0;
		actualDocument = -1;
	}
	
	public void reset(){
		this.progress = 0;
		this.actualDocument = -1;
	}
	
	public void addPropertyChangeListener(PropertyChangeListener l){
		pcs.addPropertyChangeListener(l);
	}
	
	protected void setProgress(int progress){
		int oldProgress = this.progress;
		this.progress = progress;
		
		PropertyChangeEvent event = new PropertyChangeEvent(this, PROGRESS, oldProgress, this.progress);
		pcs.firePropertyChange(event);
		
	}
	
	protected void setActualDocument(int document){
		int oldDocument = this.actualDocument;
		this.actualDocument = document;
		
		PropertyChangeEvent event = new PropertyChangeEvent(this, DOCUMENT, oldDocument, this.actualDocument);
		pcs.firePropertyChange(event);
		
	}
	
}
